#!/bin/bash
  
while getopts :l:d: ARGS  
do  
case $ARGS in   
    l)  
       lang=$OPTARG 
        ;;  
    d)  
        base=$OPTARG
        ;;  
esac
done
echo $lang;
echo $base;

if [[ ! $lang ]]|| [[ ! $base ]]; then
	echo '参数不对'
    exit 0
fi
langs=(${lang//,/ })
root=$(cd `dirname $0`; pwd)
path=$(find $root -type d -name "values-[^A-Z][a-z]")
pathL=$(find $root -type d -name "values-[^A-Z][a-z]-*")

paths=(${path[@]} ${pathL[@]})
for(( j=0;j<${#paths[@]};j++))
do
 
has="false"
for(( i=0;i<${#langs[@]};i++)) 
#${#array[@]}获取数组长度用于循环
do
if [[ ! ${langs[i]} =~ "en" ]]; then
	if [[  ${langs[i]} =~ "zh" ]]; then
		langs[i]=${langs[i]//-tw/-rTW}
		langs[i]=${langs[i]//-hk/-rHK}
		langs[i]=${langs[i]//-cn/}
	else
		langs[i]=${langs[i]: 0: 2}
	fi	 
    if [[ ${paths[j]} =~ .*${langs[i]}$ ]];then
        has="true"
    fi
fi
done;
if [[ ! ${has} == "true" ]];then
        echo ">>>: "${paths[j]}
        echo "删除"
        rm -rf ${paths[j]}
    fi
done;